/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package scheduleManager;

import app.Global;
import entities.EmployeeSchedule;
import entities.EmployeeShiftRequest;
import lib.JButtonTable.ButtonModel;

/**
 *
 * @author yoshi
 */
public class RequestButtonModel implements ButtonModel {

    private EmployeeSchedule schedule;

    public RequestButtonModel(EmployeeSchedule schedule) {
        this.schedule = schedule;
    }

    @Override
    public String getText() {
        Global.getAuth().getId();
        if (this.getSchedule().getEmployeeId() != Global.getAuth().getId()) {
            return "Not owned";
        } else {
            EmployeeShiftRequest r = this.getSchedule().getRequest();
            if (r == null) {
                return "Change";
            } else {
                switch (r.getStatus()) {
                    case 0:
                        return "Change";
                    case 1:
                        return "Pending";
                    case 2:
                        return "Approved";
                    default:
                        return "undefined";
                }
            }
        }
    }

    @Override
    public boolean isEnable() {
        if (this.getSchedule().getEmployeeId() != Global.getAuth().getId() || this.getSchedule().getRequest() != null) {
            return false;
        } else {
            return true;
        }
    }

    public EmployeeSchedule getSchedule() {
        return schedule;
    }
}
